<template>
  <table class="table">
    <thead class="table_header_title">
      <tr>
        <th>商品信息</th>
        <th>属性</th>
        <th>单价</th>
        <th>折后单价</th>
        <th>退货数量</th>
        <th>退款小计</th>
        <th>折后退款小计</th>
      </tr>
    </thead>

    <tbody class="table_tbody">
      <tr>
        <td class="noborder" colspan="7"></td>
      </tr>
      <tr>
        <td colspan="7" class="last">
          <div class="info">
            <div class="order">
              <span class="order-time">{{ formater.formatDate(tableData.orderInfo.createTime) }}</span>
              <span class="order-code">订单编号：{{ tableData.orderInfo.orderCode }}</span>
            </div>
            <div class="supplier">
              <img src="@/assets/images/dianpuxiao.png" class="store-icon" />
              <span class="supplier-name">供应商：{{ tableData.orderInfo.supplierName }}</span>
            </div>
          </div>
        </td>
      </tr>
      <tr class="goods" v-for="goods in tableData.goodsList" :key="goods.orderGoodsId">
        <td>
          <div class="goods-info">
            <img class="goods-img" :src="goods.goodsImg" />
            <span class="goods-name"> {{ goods.goodsName }}</span>
          </div>
        </td>
        <td>
          <span>{{ goods.goodsSpec }}</span>
        </td>
        <td>
          <span>¥{{ goods.backGoodsPrice.toFixed(2) }}</span>
        </td>
        <td>
          <span>¥{{ goods.backDiscountPrice.toFixed(2) }}</span>
        </td>
        <td class="amount">
          <span>{{ goods.amount }}</span>
        </td>
        <td class="goods-price last">
          <span>¥{{ (goods.backGoodsPrice * (goods.amount || 1)).toFixed(2) }}</span>
        </td>
        <td class="goods-price last">
          <span>¥{{ (goods.backDiscountPrice * (goods.amount || 1)).toFixed(2) }}</span>
        </td>
      </tr>
      <tr>
        <td class="last border" colspan="7">
          <div class="remark">
            <span class="title">退款金额</span>
            <span class="price">¥{{ sums }}</span>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</template>

<script setup>
import { reactive, toRefs, computed } from 'vue'
import formater from '@/formater'

const props = defineProps(['info', 'list'])
const { list, info } = toRefs(props)

const tableData = reactive({
  orderInfo: info,
  goodsList: list
})

const sums = computed(() => {
  let sum = tableData.goodsList.map((e) => e.amount * e.backDiscountPrice)
  return (sum.reduce((acc, cur) => cur + acc, 0)).toFixed(2)
})
</script>
<style scoped lang="scss">
.table {
  border-collapse: collapse;
  width: calc(100% - 104px);

  th {
    width: 160px;
  }
  .table_header_title {
    height: 42px;
    background-color: #f9f9f9;
    color: #909399;

    margin-bottom: 20px;
  }

  .table_tbody {
    td.noborder {
      border: 0;
      height: 20px;
    }

    td.noborder:first-child {
      border-left: none;
    }

    tr {
      td {
        line-height: 18px;
        text-align: center;
      }

      td:first-child {
        border-left: 1px solid var(--border-color);
      }

      td.last {
        border-right: 1px solid var(--border-color);
      }

      td.border {
        border-bottom: 1px solid var(--border-color);
        padding: 10px 35px 13px 54px;
        .remark {
          display: flex;
          justify-content: space-between;

          .title {
            font-weight: 500;
            line-height: 16px;
          }

          .price {
            font-weight: 600;
            line-height: 18px;
            color: var(--color-primary);
          }
        }
      }

      td.amount {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
      }

      td.goods-price {
        font-weight: 600;
        color: var(--color-primary);
      }
    }

    .info {
      display: flex;
      align-items: center;
      padding: 12px 0 12px 35px;
      height: 42px;
      box-sizing: border-box;
      border-top: 1px solid var(--border-color);
      background-color: var(--color-background);
      color: var(--color-primary-text);

      .order,
      .supplier {
        display: flex;
        align-items: center;
        height: 18px;
        line-height: 18px;
      }

      .order {
        .order-time {
          font-weight: 600;
        }

        .order-code {
          margin-left: 12px;
        }
      }

      .supplier {
        margin-left: 90px;

        .store-icon {
          width: 20px;
          height: 20px;
          margin: 0 7px 0 11px;
        }
      }
    }

    .goods {
      td {
        border-bottom: 1px solid var(--border-color);
        padding: 20px 0;

        .goods-info {
          display: flex;
          align-items: center;
          padding-left: 54px;

          .goods-img {
            display: inline-block;
            width: 72px;
            height: 72px;
            margin-right: 12px;
          }

          .goods-name {
            color: var(--color-text);
            width: 180px;
            line-height: 18px;
          }
        }
      }
    }
  }
}
</style>
